home *** CD-ROM | disk | FTP | other *** search
- /*
- GenericPatch.c
-
- Higher level patching object. Abstracts a patch as a behavior.
-
- Part of PatchWorks, the Extension Development Framework.
-
- by Mouse Herrell & Patrick Beard.
-
- Permission is granted to use this source code for any purpose, as long
- as the copyright notice is maintained.
-
- © 1992 Berkeley Systems, Inc.
- */
-
- #include "GenericPatch.h"
-
- void GenericPatch::InitGenericPatch(short trap, long resultOffset)
- {
- TrapPatch::InitTrapPatch(GetDispatcher(), trap);
- itsFrame = nil;
- itsResultOffset = resultOffset;
- }
-
- void GenericPatch::Behavior() {}
- PatchProcPtr GenericPatch::GetDispatcher() { return &GenericPatch::Dispatch; }
-
- void GenericPatch::AbortTrap()
- {
- // adjust the stack back to caller's address.
- itsFrame->offset = itsFrame->parameters + itsResultOffset;
- }
-
- // default trap dispatching routine.
- // if you override GetBehavior above, you can have your behavior routine
- // executed directly, with the stack layed out the way you want.
-
-
- void GenericPatch::Dispatch(PatchFrame frame)
- {
- GenericPatch* thisPatch;
- PatchFrame* oldFrame;
-
- #if defined(THINK_C) && !__option(a4_globals)
- #define cDebuggerName "\pTHINK C Debugger 5.0"
- if (EqualString(CurApName, cDebuggerName, false, false))
- return; // don't get in debugger's way.
- #endif
-
- thisPatch = (GenericPatch*)frame.patch;
- oldFrame = thisPatch->itsFrame;
- thisPatch->itsFrame = &frame;
- thisPatch->Behavior();
- thisPatch->itsFrame = oldFrame;
- }
-
- void GenericVectorPatch::InitGenericVectorPatch(PatchVectorPtr vector, long resultOffset)
- {
- VectorPatch::InitVectorPatch(GetDispatcher(), vector);
- itsResultOffset = resultOffset;
- }
-
- void GenericVectorPatch::Behavior() {}
- PatchProcPtr GenericVectorPatch::GetDispatcher() { return &GenericVectorPatch::Dispatch; }
-
- void GenericVectorPatch::AbortVector()
- {
- // adjust the stack back to caller's address.
- itsFrame->offset = itsFrame->parameters + itsResultOffset;
- }
-
- // default trap dispatching routine.
- // if you override GetBehavior above, you can have your behavior routine
- // executed directly, with the stack layed out the way you want.
-
- void GenericVectorPatch::Dispatch(PatchFrame frame)
- {
- GenericVectorPatch* thisPatch = (GenericVectorPatch*)frame.patch;
- #if defined(THINK_C) && !__option(a4_globals)
- if (EqualString(CurApName, cDebuggerName, false, false))
- return; // don't get in debugger's way.
- #endif
- thisPatch->itsFrame = &frame;
- thisPatch->Behavior();
- }
-